
//
//  DetailViewController.swift
//  SinaNews
//
//  Created by hroot on 15/8/17.
//  Copyright (c) 2015年 Lily. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController, UIWebViewDelegate {

    var url: String?
    var webView: UIWebView?
    var containerController: AppContainerViewController?
    override func viewDidLoad() {
        super.viewDidLoad()

        creatWebView()
        creatButtonItems()
    }
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.automaticallyAdjustsScrollViewInsets = false
    }
    
    func creatWebView(){
        self.webView = UIWebView(frame: CGRectMake(0, 64, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height-64))
        var request = NSURLRequest(URL: NSURL(string: self.url!)!)
        self.webView?.loadRequest(request)
        self.webView?.delegate = self
        self.view.addSubview(self.webView!)
    }
    func creatButtonItems() {
        var arr = ["navigationbar_back_icon@2x","navigationbar_share_icon@2x","navigationBarItem_favorite_normal@2x","navigationBarItem_like_normal@2x"]
        var leftItems = NSMutableArray()
        var rightItems = NSMutableArray()
        for (var i = 0; i < arr.count; i++) {
            var image = UIImage(named: arr[i])
            var item = UIBarButtonItem(image: image, style: UIBarButtonItemStyle.Plain, target: self, action: "itemClick")
            item.tag = 201+i
            if (item.tag == 201) {
                leftItems.addObject(item)
            } else {
                rightItems.addObject(item)
            }
        }
        self.containerController!.navigationItem.leftBarButtonItems = leftItems as [AnyObject]
        self.containerController!.navigationItem.rightBarButtonItems = rightItems as [AnyObject]
    }
    func itemClick(item: UIBarButtonItem) {
        switch item.tag {
        case 201:
            self.containerController!.navigationController!.popViewControllerAnimated(true)
        case 202:
            println("点赞")
        case 203:
            println("收藏")
        case 204:
            println("分享")
        default:
            break
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
